<?php
class mysql
{
    function connect($db)
    {
        echo "连接到数据库{$db}".PHP_EOL;
    }
}
class sqlproxy
{
    private $target;
    public function __construct($tar)
    {
        $this->target = new $tar;
    }
    public function __call($name,$args)
    {
        $r = new ReflectionClass($this->target);
        if($method = $r->getMethod($name))
        {
            if($method->isPublic() && !$method->isAbstract())
            {
                echo "方法前拦截".PHP_EOL;
                $method->invoke($this->target,...$args);
                echo "方法后拦截".PHP_EOL;
            }
        }
    }
}
$obj = new sqlproxy('mysql');
$obj->connect('hook');